import { post, get } from '@/utils/request'
import { buildUrl } from '@/utils/url.js'
import storage from '@/utils/storage'

// 引入moment.js库
import moment from 'moment';


export function sub5Hours(currentTime) {
	const currentTimeType = storage.get('CURRENT_TIME_TYPE')

	const givenTimeStr = currentTime
	if (!givenTimeStr) {
		return null
	}

	// 判断是否为时间戳（数字类型或纯数字字符串）
	let givenTime;
	let isDateOnly = false;

	if (typeof givenTimeStr === 'number' || /^\d+$/.test(givenTimeStr)) {
		givenTime = moment(parseInt(givenTimeStr));
		// 检查是否为秒级时间戳
		if (typeof givenTimeStr === 'number' && givenTimeStr < 10000000000) {
			// 秒级时间戳转毫秒
			givenTime = moment(parseInt(givenTimeStr) * 1000);
		} else {
			givenTime = moment(parseInt(givenTimeStr));
		}
	} else {
		givenTime = moment(givenTimeStr);
		// 检查是否只包含日期部分（没有时间部分）
		if (givenTimeStr.match(/^\d{4}-\d{2}-\d{2}$/) ||
			givenTimeStr.match(/^\d{4}\/\d{2}\/\d{2}$/)) {
			isDateOnly = true;
		}
	}

	// 无论 currentTimeType 的值是多少，都先转换为正常时间再减5小时
	if (currentTimeType === 1 || currentTimeType === '1') {
		const processedTime = givenTime.subtract(5, 'hours');
		if (isDateOnly) {
			return processedTime.format('YYYY-MM-DD');
		} else {
			return processedTime.format('YYYY-MM-DD HH:mm');
		}
	} else {
		// 即使 currentTimeType 不是1，也返回格式化后的时间
		if (isDateOnly) {
			return givenTime.format('YYYY-MM-DD');
		} else {
			return givenTime.format('YYYY-MM-DD HH:mm');
		}
	}
}



export function isLessThanOrEqualToEndOfNextMonth(currentTime) {
	//console.log("比较时间：",currentTime)
	if (!currentTime) {
		return false
	}

	// 处理时间戳格式（数字类型或纯数字字符串）
	let bijiao
	if (typeof currentTime === 'number' || /^\d+$/.test(currentTime)) {
		bijiao = new Date(parseInt(currentTime))
	} else {
		bijiao = new Date(currentTime)
	}

	const today = new Date()
	const nextMonth = new Date(today.getFullYear(), today.getMonth() + 2, 0) // 下个月的月底
	//console.log("比较的时间",bijiao,"当前时间：", today,  "下个月的月底：", nextMonth, "当前时间小于下个月的月底：", currentTime < nextMonth);
	return bijiao < nextMonth
}



export function isGreaterThanCurrentDay(day) {
	// 如果传入的是字符串，尝试转换为数字
	if (typeof day === 'string') {
		day = parseInt(day, 10);
	}

	// 验证是否为有效数字且在合理范围内(1-31)
	if (typeof day !== 'number' || isNaN(day) || day < 1 || day > 31) {
		console.log("无效的日期参数:", day);
		return false;
	}
	const today = new Date();
	const currentDay = today.getDate(); // 获取当前是几号(1-31)

	//console.log("当前时间：", today, "当前是几号(1-31)：", currentDay, "传入参数:", day);

	// 返回当前日期是否大于等于传入的日期
	return currentDay >= day;
}

export function loadVehicleData (data) {

	return post('/ztc/vehicle/list', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}


export function processList (data) {

	return post('/ztc/order/processList', Object.assign({
		orderType: null
	}, data))
}

export function shenheCangkuInfo (data) {

	return post('/ztc/cangku/shenheCangkuInfo',data)
}

export function shenheCarInfo (data) {
	return post('/ztc/cangku/shenheCarInfo', data)
}

export function loadOrderListData (data) {

	return post('/ztc/order/list', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}


export function loadDeliveryOrderListData (data) {

	return post('/ztc/delivery/order/list', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}

export function loadMyOrderListData (data) {

	return post('/ztc/order/myList', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}



export function loadCangkuListData (data) {

	return post('/ztc/cangku/list', Object.assign({
		pageNo: 0,
		expire:null,
		pageSize: 20,
		queryParam: null,
		rentType:null,
		requestData: {
		}
	}, data))
}


export function shenheList (data) {

	return post('/ztc/cangku/shenheList', Object.assign({
		pageNo: 0,
		expire:null,
		pageSize: 20,
		queryParam: null,
		rentType:null,
		requestData: {
		}
	}, data))
}
export function addCangkuInfo (data) {
	return post('/ztc/cangku/addOrUpdateCangku', data)
}


export function deleteCangkuById (data) {
	return post('/ztc/order/deleteOrderByIdNew',Object.assign({
		orderId: 0,
		orderPics: [],
	}, data))
}


export function selectCangkuById (id) {
	return get('/ztc/cangku/'+id)
}

export function deleteTCangkuListByOrderId (id) {
	return get('/ztc/cangku/delete/'+id)
}

export function getIqamaRecords (userId) {
	return get('/ztc/order/getIqamaRecords/'+userId)
}



export function getMaintenanceRecords (data) {

	return post('/ztc/car/getMaintenanceInfo', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		expire:null,
		carId:null,
		queryType:null,
		type:null,
		requestData: {
		}
	}, data))
}

export function loadCarListData (data) {

	return post('/ztc/car/list', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		expire:null,
		requestData: {
		}
	}, data))
}

export function loadDeliveryCarListData (data) {

	return post('/ztc/delivery/car/list', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		expire:null,
		requestData: {
		}
	}, data))
}

export function addCarInfo (data) {
	return post('/ztc/car/addOrUpdateCar', data)
}


export function addDeliveryCarInfo (data) {
	return post('/ztc/delivery/car/addOrUpdateCar', data)
}


export function deleteCarById (id) {
	return get('/ztc/car/delete/'+id)
}



export function selectCarById (id) {
	return get('/ztc/car/'+id)
}

export function deleteTCrByOrderId (warehouseId) {
	return get('/ztc/car/delete/'+warehouseId)
}


export function deleteDeliveryTCrByOrderId (warehouseId) {
	return get('/ztc/delivery/car/delete/'+warehouseId)
}


export function loadDeptNameData (data) {

	return post('/ztc/order/getSelectDepts', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}

export function loadSelectUserList (data) {
	if(data){
		return post('/ztc/order/getSelectUsers?queryParam='+data, Object.assign({
			pageNo: 0,
			expire:null,
			pageSize: 1000,
			queryParam: null,
			nickName:null,
			requestData: {
			}
		}, data))
	}else {
		return post('/ztc/order/getSelectUsers', Object.assign({
			pageNo: 0,
			pageSize: 1000,
			queryParam: null,
			nickName:null,
			requestData: {
			}
		}, data))
	}

}


export function loadSelectCarList (data) {
	return post('/ztc/delivery/order/getSelectCars?queryParam='+data, Object.assign({
		pageNo: 0,
		expire:null,
		pageSize: 1000,
		queryParam: null,
		nickName:null,
		requestData: {
		}
	}, data))
}

export function loadSelectMileageCarList (data) {
	return post('/ztc/car/mileage/getSelectMileageCars?queryParam='+data, Object.assign({
		pageNo: 0,
		expire:null,
		pageSize: 1000,
		queryParam: null,
		nickName:null,
		requestData: {
		}
	}, data))
}

export function getSelectTelephones (data) {
	return post('/ztc/delivery/order/getSelectTelephones', Object.assign({
		pageNo: 0,
		expire:null,
		pageSize: 1000,
		queryParam: null,
		nickName:null,
		requestData: {
		}
	}, data))
}
export function getAllUsers (data) {
	return post('/ztc/order/getAllUsers', Object.assign({
		pageNo: 0,
		expire:null,
		pageSize: 1000,
		queryParam: null,
		nickName:null,
		requestData: {
		}
	}, data))
}

export function deleteOrderById (data) {
	return post('/ztc/order/deleteOrderByIdNew',Object.assign({
		orderId: 0,
		orderPics: [],
	}, data))
}


export function deleteDeliveryOrderById (data) {
	return post('/ztc/delivery/order/deleteOrderByIdNew',Object.assign({
		orderId: 0,
		orderPics: [],
	}, data))
}

export function completeOrderById (data) {

	return post('/ztc/order/completeOrderByIdNew',Object.assign({
		orderId: 0,
		orderPics: [],
	}, data))
}


export function getOrderDetailById (id) {
	return get('/ztc/order/getOrderDetail/'+id)
}


export function getOrderData (id) {
	return get('/ztc/order/getOrderData')
}

export function getUserInfo (id) {
	return get('/ztc/order/userInfo/'+id)
}
export function loadMyVehicleData (data) {

	return post('/ztc/vehicle/myList', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}
export function loadSeeVehicleData (data) {

	return post('/ztc/vehicle/mySeeList', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}

export function loadShenheVehicleData (data) {

	return post('/ztc/vehicle/myShenheList', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}

export function myCollectList (data) {

	return post('/ztc/vehicle/myCollectList', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}
export function getTuijianList (data) {

	return post('/ztc/vehicle/getTuijianList', Object.assign({

	}, data))
}

export function getNewList (data) {

	return post('/ztc/vehicle/getNewList', Object.assign({

	}, data))
}


export function getVehicleDetail (orderId) {
	//console.log("DATA==========",orderId)
	return get('/ztc/order/'+orderId)
}

export function updateHitCount (vehicleId) {
	//console.log("DATA==========",vehicleId)
	return post('/ztc/vehicle/updateHitCount/'+vehicleId)
}

export function insertSeeRecord (vehicleId) {
	//console.log("DATA==========",vehicleId)
	return post('/ztc/vehicle/insertSeeRecord/'+vehicleId)
}

export function loadVehicleById (data) {
	return post('/ztc/vehicle/list', Object.assign({
		pageNo: 0,
		pageSizes: 20,
		queryParam: null,
		requestData: {
		}
	}, data))
}


export function getInviteList (data) {
	return post('/ztc/vehicle/getInviteList', Object.assign({

	}, data))
}

export function addOrderInfo (data) {
	return post('/ztc/order/add', data)
}

export function addDeliveryOrderInfo (data) {
	return post('/ztc/delivery/order/add', data)
}

export function addDeliveryOrderDetailInfo (data) {
	return post('/ztc/delivery/order/detail/add', data)
}
export function saveOrUpdateUser (data) {
	return post('/ztc/order/saveOrUpdateUser', data)
}

export function saveOrUpdateUserTimeType (data) {
	return post('/ztc/order/saveOrUpdateUserTimeType', data)
}

export function checkIfHasCharge (data) {
	return post('/ztc/order/checkIfHasCharge', data)
}
export function chargeOrderInfo (data) {
	return post('/ztc/order/chargeOrderInfo', data)
}

export function updateTVehicleInfo (data) {
	return post('/ztc/vehicle/updateTVehicleInfo', Object.assign({
		drivingImage: [],
        drivingImageCopy: [],
        drivingFrontImage: null,
        drivingCopyImage: null,
        vehiclePics:[],
        computerPics:[],
        cheesePics:[],
        cheeseBrandPics:[],
        brandPics:[],
        brunkPics:[],
        ownerPaperPics:[],
        otherPics:[],
        picList:[],
        name: '',
        phone: '',
        code: '',
        vehicleType: '',
        vehicleModel: '',
        number: '',
        leasingCompanyId: '',
        leasingCompanyName: '',
        price: '',
        description: '',
        isSell: true,
        username:null,
        smsCode:null,
        vehicleDescribe:null,
        markPrice:null,
        vehicleBrand:null,
        chassisBrand:null,
        vehicleAxis:null,
        guohuFlag:null,
        daikuanFlag:null,
        chuchangYear:null,
        vehicleLocaltion:null,
        paifangLevel:null,
        armSegment:null,
        vehicleId:null,
		vehicleStatus:null
	}, data))
}
export function checkSms (data) {
	return post('/ztc/vehicle', Object.assign({
		drivingFrontImage: null,
		drivingCopyImage: null,
		name: '',
		phone: '',
		code: '',
		vehicleType: '',
		vehicleModel: '',
		number: '',
		leasingCompanyId: '',
		leasingCompanyName: '',
		price: '',
		description: '',
		isSell: true,
		username:null,
		smsCode:null
	}, data))
}

export function createOrder (data) {
	return post('/htnweapp/createOrUpdateOrder', Object.assign({
		orderInfo: null,
		orderInfoImage: null,
		constructionPosition: null, // 施工部位信息
		expectVolume: null, // 预计方量
		itemId: null, // 项目ID
		itemName: null, //项目名称
		itemPosition: null, // 项目施工位置
		lat: null, // 项目施工位置 纬度
		linkmanId: null, // 联系人ID
		linkmanName: null, // 联系人名称
		linkmanTelephone: null ,// 联系人电话
		linkmanType: 2, // 0 工长 1 项目负责人 2. 联系人
		lng: null, // 项目施工位置 经度
		orderRemarks: null, // 备注列表
		picList: null, // 支泵位置图片列表
		reachTime: null, // 到达时间
		remark: null, // 订单备注
		selectedVehicles: null // 指定车辆列表
	}, data))
}

export function updateOrderDetail (data) {
	return post('/htnweapp/updateOrderInfo', Object.assign({
		orderInfo: null,
		orderInfoImage: null,
		constructionPosition: null, // 施工部位信息
		expectVolume: null, // 预计方量
		itemId: null, // 项目ID
		itemName: null, //项目名称
		itemPosition: null, // 项目施工位置
		lat: null, // 项目施工位置 纬度
		linkmanId: null, // 联系人ID
		linkmanName: null, // 联系人名称
		linkmanTelephone: null ,// 联系人电话
		linkmanType: 2, // 0 工长 1 项目负责人 2. 联系人
		lng: null, // 项目施工位置 经度
		orderRemarks: null, // 备注列表
		picList: null, // 支泵位置图片列表
		reachTime: null, // 到达时间
		remark: null, // 订单备注
		/**
		 * [{
			"vehicleId": null,
			"vehiclePlate":"津A56789",
			"vehicleType":"天泵",
			"vehicleModel":"38米",
			"outsideLeasingFlag":1,
			"leasingCompanyId":"1439059948062875652",
			"leasingCompanyName":"李小心租赁公司"
		 }]
		 */
		selectedVehicles: null // 指定车辆列表
	}, data))
}

export function updateOrder (data) {
	return post('/htnweapp/createOrUpdateOrder', Object.assign({
		id: null,
		constructionPosition: null, // 施工部位信息
		expectVolume: null, // 预计方量
		imeiNum: null, // 车辆Imei号码
		itemId: null, // 项目ID
		itemName: null, //项目名称
		itemPosition: null, // 项目施工位置
		lat: null, // 项目施工位置 纬度
		linkmanId: null, // 联系人ID
		linkmanName: null, // 联系人名称
		linkmanTelephone: null ,// 联系人电话
		linkmanType: null, // 0 工长 1 项目负责人 2. 联系人
		lng: null, // 项目施工位置 经度
		orderRemarks: null, // 备注列表
		picList: null, // 支泵位置图片列表
		reachTime: null, // 到达时间
		remark: null, // 订单备注
		selectedVehicles: null // 指定车辆列表
	}, data))
}

export function getOrderDetail (id) {
	return get('/htnweapp/getOrderDetail', {
		orderId: id
	})
}

export function loadOrderData (data) {
	return post('/htnweapp/selectOrderInfoList', Object.assign({
		pageNo: 0,
		pageSize: 20,
		requestData: {
		}
	}, data))
}
// 订单角标
export function loadOrderDataCount (data) {

}

export function cancelOrder (data) {
	return post('/htnweapp/cancelPumpOrder', Object.assign({
		orderId: null,
		orderType: 1,
		type: 1,
		cancelReason: null
	}, data))
}

export function updateOrderReachTime (data) {
	return post('/htnweapp/updateOrderInfo', Object.assign({
		orderId: null,
		requestId: null,
		reachTime: null
	}, data))
}

/**
 * 更新施工信息
 */
export function updateOrderBuildInfo (data) {
	return post('/htnweapp/updateOrderInfo', Object.assign({
		// constructionPosition: null, // 施工部位信息
		// expectVolume: null, // 预计方量
		// linkmanId: null, // 联系人ID
		// linkmanName: null, // 联系人名称
		// linkmanTelephone: null ,// 联系人电话
		// linkmanType: 2, // 0 工长 1 项目负责人 2. 联系人
		// remark: null, // 订单备注
		orderId: null, // 订单编号
	}, data))
}

export function createOrderRemark (data) {
	return post(buildUrl('/htnweapp/addOrderRemark', Object.assign({
		orderRemark: null
	}, data)))
}

export function loadOrderRemarkData () {
	return get('/htnweapp/getRecentRemark')
}

export function loadOrderLogData (id) {
	return get('/htnweapp/getOrderRecord', {
		orderId: id
	})
}

export function createOrderComment (data) {
	return post(buildUrl('/htnweapp/addCommentToOrder', Object.assign({
		comment: '',
		orderId: null
	}, data)))
}

/**
 * 获取子订单信息
 */
export function getSubOrderDetail (data) {
	const { orderId, subOrderId } = data
	return get('/htnweapp/getOrderDetail', {
		orderId
	}).then(rs => {
		return (rs.orderInfoList || []).find(v => v.vehicleId === subOrderId)
	})
}

/**
 * 修改子订单信息
 */
export function updateSubOrder (data) {
	/**
	 * {
		relationId: null,
		picList: null,
		endTime: null,
		startTime: null,
		concretePlantName: null,
		driverVolume: null
	 }
	 */
	return post('/htnweapp/updateDriverVolumeByOrderId', data)
}

/**
 * 完成子订单
 */
export function completeSubOrder (data) {
	return post('/htnweapp/completeOrderInfo', Object.assign({
		orderId: null,
		relationId: null,
		remark: null,
		driverVolume: null,
		endTime: null,
		startTime: null,
		picList: []
	}, data))
}

/**
 * 取消子订单
 */
export function cancelSubOrder (data) {
	return post('/htnweapp/cancelPumpOrder', Object.assign({
		cancelReason: null,
		orderType: 1,
		type: 0,
		orderId: null,
		requestId: null
	}, data))
}

/**
 * 完善自订单租车信息
 */
export function replenishSubOrderCarInfo (data) {
	return post('/htnweapp/completeRentalVehicle', Object.assign({
		id: null,
		orderId: null,
		/**
		 * {
			driverName: null,
			driverTel: null,
			id: null
		 }
		 */
		rentalDriverVOS: []
	}, data))
}

/**
 * 调整订单车辆信息
 */
export function updateOrderCarInfo (data) {
	return post('/htnweapp/changeOrderVehicleInfo', Object.assign({
		/**
		 * {
			id: null,
			vehicleModel: null,
			vehicleType: null,
			...
		 }
		 */
		addVehicles: [],
		/**
		 * {
			cancelReason: null,
			id: null,
			vehicleModel: null,
			vehicleType: null,
			...
		 }
		 */
		deleteVehicles: [],
		orderId: null
	}, data))
}

/**
 * 查询订单车辆信息
 */
export function loadOrderBindCarData (id) {
	return get('/htnweapp/findSelectedVehicles', {
		orderId: id
	})
}

/**
 * 完善租车信息
 */
export function replenishRentalCarInfo (data) {
	return post('/htnweapp/completeRentalVehicle', Object.assign({
		orderId: null,
		id: null,
		/**
		 * {
			driverName: null,
			driverTel: null,
			id: null
		 }
		 */
		rentalDriverVOS: []
	}, data))
}

/**
 * 查询是否位置纠错
 */
export function loadSituationReportInfoData (orderId) {
	return post(`/htnweapp/querSituationReportInfo?orderId=${orderId}`)
}

/**
 * 同意或不同意纠错位置
 */
export function receiveOrRefuseLocation (data) {
	const { id, flag } = data
	return post(`/htnweapp/receiveOrRefuseLocation?id=${id}&flag=${flag}`)
}

/**
 * 获取纠错位置申请
 */
export function getSituationReportInfo (data) {
	const { orderId, id } = data
	return post(`/htnweapp/querSituationReportInfo?orderId=${orderId}`).then(rs => {
		return (rs || []).find(v => v.id === id)
	})
}

/**
 * 查询常用施工部位
 */
export function loadOrderConstructionPositionData () {
	return post('/htnweapp/queryRecentsPositionlist')
}

/**
 * 新增订单备忘录
 */
export function createOrderMemo (data) {
	return post('/htnweapp/saveOrUpdateNoteInfo', {
		note: data
	})
}

/**
 * 加载订单备忘录数据
 */
export function loadOrderMemoData (data) {
	return get('/htnweapp/queryNoteInfo', Object.assign({
		queryParam: null
	}, data))
}

/**
 * 获取订单备忘录数据
 */
export function getOrderMemoData (memoId) {
	return get('/htnweapp/queryNoteInfo').then(rs => {
		const item = (rs || []).find(v => v.id === memoId)
		if (item) {
			return item
		} else {
			return Promise.reject()
		}
	})
}

/**
 * 获取订单备忘录总数
 */
export function getOrderMemoCount () {
	return loadOrderMemoData().then(rs => {
		return rs ? rs.length : 0
	})
}

/**
 * 删除订单备忘录数据
 */
export function deleteOrderMemoData (id) {
	return post(`/htnweapp/deleteNoteInfo?id=${id}`)
}

/**
 * 识别文本以及图片中的项目订单信息
 */
export function ocrConstructionInfo (data) {
	return post('/common/anylizeConstructionInfo', Object.assign({
		content: ''
	}, data))
}

/**
 * 增加订单注意事项
 * */
export function createOrderMatter (data) {
	return post('/common/addItemMatters', Object.assign({
		note: null,
		picList: null
	}, data))
}

/**
 * 加载订单注意事项
 */
export function loadOrderMatterData (data) {
	return get('/common/queryItemMatters', Object.assign({
		itemId: null
	}, data))
}

/**
 * 校验是否关注公众号
 */
export function checkIfAttention () {
	return get('/common/checkIfGuanzhu')
}






export function loadVehicleStatus (data) {
		return  [
		{
			label: '全部',
			name: ''
		},
		{
			label: '审核中',
			name: '1'
		},
		{
			label: '审核完成',
			name: '2'
		}
	];

}


export function selectDeliveryCarById (carId) {
	return get('/ztc/delivery/car/'+carId)
}
export function getDeliveryOrderDetailById (id) {
	return get('/ztc/delivery/order/getOrderDetail/'+id)
}


export function getOrderDeliveryDetail (id) {
	return get('/ztc/delivery/order/getOrderDeliveryDetail/'+id)
}


export function updateOrderPics (data) {
	return post('/ztc/delivery/order/updateOrderPics', data)
}

export function updateOrderLeavePics (data) {
	return post('/ztc/delivery/order/updateOrderLeavePics', data)
}

export function deleteOrderDetailByOrderId (data) {
	return post('/ztc/delivery/order/deleteTCrByOrderId/'+data, data)
}




export function addOrUpdateMaintenance (data) {
	return post('/ztc/car/addOrUpdateMaintenance', data)
}

export function getMaintenanceById (warehouseId) {
	return get('/ztc/car/mantenance/'+warehouseId)
}
export function deleteMaintenanceById (data) {
	return get('/ztc/car/maintenance/delete/'+data)
}

export function getUserInfoById (data) {
	return get('/ztc/order/userInfo/'+data)
}



export function addMileageInfo (data) {
	return post('/ztc/car/mileage/addOrUpdateCar', data)
}
export function loadMileageCarListData (data) {

	return post('/ztc/car/mileage/list', Object.assign({
		pageNo: 0,
		pageSize: 20,
		queryParam: null,
		expire:null,
		requestData: {
		}
	}, data))
}


export function selectMileCarById (carId) {
	return get('/ztc/car/mileage/'+carId)
}
export function deleteMileageByOrderId (warehouseId) {
	return get('/ztc/car/mileage/delete/'+warehouseId)
}

export function getOverviewCountData (data) {
	return post('/ztc/delivery/order/querStatisticInformation', Object.assign({
		type: null, // 1.月 2.年 3 自定义
		endTime: null,
		startTime: null,
		realMonth: null,
		realYear: null,
		vehicleOwnType: null,
		vehicleType: null
	}, data))
}

export function calculateDuration(startTime, endTime) {
	// 检查时间参数是否存在
	if (!startTime || !endTime) {
		return '';
	}

	// 处理不同格式的时间参数
	const parseTime = (time) => {
		if (typeof time === 'number' || /^\d+$/.test(time)) {
			// 时间戳格式（毫秒）
			return parseInt(time);
		} else {
			// 日期字符串格式
			return new Date(time).getTime();
		}
	};

	const start = parseTime(startTime);
	const end = parseTime(endTime);

	// 计算时间差（毫秒）
	const diff = end - start;

	// 转换为小时和分钟
	const hours = Math.floor(diff / (1000 * 60 * 60));
	const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));

	// 返回格式化字符串
	return `${hours}小时 ${minutes}分钟`;
}


export function timestampToTime  (stamp) {
	let date = new Date(stamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
	let Y = date.getFullYear() + '-',
		M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-',
		D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ',
		h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':',
		m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':',
		s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
	return Y + M + D+ h + m + s;
}

export function formatTime(timestamp) {
	if (!timestamp) return '';
	const date = new Date(timestamp);
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	const hours = String(date.getHours()).padStart(2, '0');
	const minutes = String(date.getMinutes()).padStart(2, '0');
	const seconds = String(date.getSeconds()).padStart(2, '0');

	return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
